<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>&#39;B站评论&#39; | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="import urllib.requestimport urllib.parseimport http.cookiejarimport gzipimport json def crawler():    url &#x3D; “https:&#x2F;&#x2F;api.bilibili.com&#x2F;x&#x2F;v2&#x2F;reply&#x2F;add&quot;    headers &#x3D; {        “Accept”: “application&#x2F;">
<meta property="og:type" content="article">
<meta property="og:title" content="&#39;B站评论&#39;">
<meta property="og:url" content="http://yoursite.com/2020/04/25/B%E7%AB%99%E8%AF%84%E8%AE%BA/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="import urllib.requestimport urllib.parseimport http.cookiejarimport gzipimport json def crawler():    url &#x3D; “https:&#x2F;&#x2F;api.bilibili.com&#x2F;x&#x2F;v2&#x2F;reply&#x2F;add&quot;    headers &#x3D; {        “Accept”: “application&#x2F;">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-04-25T03:14:29.000Z">
<meta property="article:modified_time" content="2020-04-25T03:14:56.257Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-B站评论" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/04/25/B%E7%AB%99%E8%AF%84%E8%AE%BA/" class="article-date">
  <time datetime="2020-04-25T03:14:29.000Z" itemprop="datePublished">2020-04-25</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      &#39;B站评论&#39;
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>import urllib.request<br>import urllib.parse<br>import http.cookiejar<br>import gzip<br>import json</p>
<p>def crawler():<br>    url = “<a href="https://api.bilibili.com/x/v2/reply/add&quot;" target="_blank" rel="noopener">https://api.bilibili.com/x/v2/reply/add&quot;</a><br>    headers = {<br>        “Accept”: “application/json, text/javascript, <em>/</em>; q=0.01”,<br>        “Accept-Encoding”: “gzip, deflate, br”,<br>        “Accept-Language”: “zh-CN,zh;q=0.9,en;q=0.8”,<br>        “Connection”: “keep-alive”,<br>        “Content-Type”: “application/x-www-form-urlencoded; charset=UTF-8”,<br>        “Cookie”: “_uuid=A674206E-E048-2012-1032-BF0FD75BC70E99970infoc; buvid3=F4A09182-27A1-4DAD-8F93-C3164E9CAF9053914infoc; sid=6rxdamki; im_notify_type_478149120=0; CURRENT_FNVAL=16; LIVE_BUVID=AUTO4915829617489886; rpdid=|(J|YkRm|Ruk0J’ul)kmYu~l|; DedeUserID=478149120; DedeUserID__ckMd5=b117727f75a94a18; SESSDATA=50d5ba27%2C1601444487%2Cc9727*41; bili_jct=fda4acd2a3e2f0fa699ee9e33bbdc774; CURRENT_QUALITY=80; bp_t_offset_478149120=377922904044417661; PVID=1”,<br>        “Host”: “api.bilibili.com”,<br>        “Origin”: “<a href="https://www.bilibili.com&quot;" target="_blank" rel="noopener">https://www.bilibili.com&quot;</a>,<br>        “Referer”: “<a href="https://www.bilibili.com/video/BV1pV411Z7RC&quot;" target="_blank" rel="noopener">https://www.bilibili.com/video/BV1pV411Z7RC&quot;</a>,<br>        “Sec-Fetch-Dest”: “empty”,<br>        “Sec-Fetch-Mode”: “cors”,<br>        “Sec-Fetch-Site”: “same-site”,<br>        “User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36”,<br>    }<br>    form_data = {<br>        “oid”: 412845071,<br>        “type”: 1,<br>        “message”: “你想回学校了吗？”,<br>        “plat”: 1,<br>        “jsonp”: “jsonp”,<br>        “csrf”: “fda4acd2a3e2f0fa699ee9e33bbdc774”<br>    }</p>
<pre><code>data = bytes(urllib.parse.urlencode(form_data),encoding=&quot;utf-8&quot;)
r = urllib.request.Request(url=url,data=data,headers=headers)
cookie = http.cookiejar.CookieJar()
handler = urllib.request.HTTPCookieProcessor(cookie)
opener = urllib.request.build_opener(handler)
#urllib.request.install_opener(opener)
response = opener.open(r)
resp = gzip.GzipFile(fileobj=response)
print(resp.read().decode(&quot;utf-8&quot;))</code></pre><p>crawler()</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/04/25/B%E7%AB%99%E8%AF%84%E8%AE%BA/" data-id="ck9frj1k30004hgv12bdq3cxv" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/04/25/%E5%BF%85%E5%BA%94%E7%BF%BB%E8%AF%91/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          &#39;必应翻译&#39;
        
      </div>
    </a>
  
  
    <a href="/2020/04/25/B%E7%AB%99%E8%AF%84%E8%AE%BA-ruquests%E2%80%99/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">&#39;B站评论_ruquests’</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">April 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/02/">February 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2020/04/25/%E7%AC%94%E8%AE%B0/">&#39;笔记&#39;</a>
          </li>
        
          <li>
            <a href="/2020/04/25/%E6%8F%90%E5%8F%96IP%E4%BF%A1%E6%81%AF/">&#39;提取IP信息&#39;</a>
          </li>
        
          <li>
            <a href="/2020/04/25/%E5%BF%85%E5%BA%94%E7%BF%BB%E8%AF%91/">&#39;必应翻译&#39;</a>
          </li>
        
          <li>
            <a href="/2020/04/25/B%E7%AB%99%E8%AF%84%E8%AE%BA/">&#39;B站评论&#39;</a>
          </li>
        
          <li>
            <a href="/2020/04/25/B%E7%AB%99%E8%AF%84%E8%AE%BA-ruquests%E2%80%99/">&#39;B站评论_ruquests’</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>